/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.opencourse.controlador;

import com.opencourse.entidades.Usuario;
import com.opencourse.modelo.UsuarioFacade;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ApplicationScoped;

/**
 *
 * @author jonathan
 */
@ManagedBean
@ApplicationScoped
public class login {

    @EJB
    private UsuarioFacade usuarioFacade;

    public login() {
    }
    
    private String loginname;
    private String password;

    public String getLoginname() {
        return loginname;
    }

    public void setLoginname(String loginname) {
        this.loginname = loginname;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

//    public String CheckValidUser() {
//        if (loginname.equals("jonathany23") && password.equals("1234")) {
//            System.out.println("jonathany23");
//            return "pages/test2";
//        } else {
//            return "fail";
//        }
//    }

    public String obtenerUsuarios() {
        List<Usuario> us = new ArrayList<Usuario>();
        us = usuarioFacade.findAll();
        for (Usuario usuario : us) {
            if ((usuario.getUsername().equals(loginname))&&(usuario.getPassword().equals(password))) {
                return "pages/Cursos";
            }
        }
        return "fail";
    }
    /**
     * Creates a new instance of login
     */
}
